package stage
{
	import edu.pku.component.RfidInfoBox;
	
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	import mx.managers.PopUpManager;
	
	public class RfidReaderSubject extends SandTableSubject
	{
		public var rfidInfoBox:RfidInfoBox=new RfidInfoBox();
		
		public function RfidReaderSubject(id:String)
		{
			super(id, AppConstant.TYPE_RFID_READER);
			this.displayOrder=AppConstant.ORDER_BOTTOM;
			this.removeEventListener(MouseEvent.CLICK,openInfoWindow);
			this.addEventListener(MouseEvent.CLICK,openRfidWindow);
			
			var nimbusInstance:NimbusSprite=NimbusSprite.createNimbusSprite(AppConstant.TYPE_RFID_READER);
			//var ImageProtypeClass:Class=ResourceManager.RfidReader;
			//var imageInstance:DisplayObject=new ImageProtypeClass() as DisplayObject;
			addChild(nimbusInstance);
		}
		
		/**
		 * open a rfid window show RFID code and  RFID subject name 
		 * @param event
		 */
		protected function openRfidWindow(event:MouseEvent):void
		{
			var point:Point=new Point();
			point.x=event.stageX;
			point.y=event.stageY;
			showThisWindow(point);
		}
		
		public override function clearHistoryRecords():void
		{
			this.rfidInfoBox.clearHistoryData();
		}
		
		protected function showThisWindow(point:Point):void
		{
			if(!rfidInfoBox.opened)
			{
				rfidInfoBox.opened=true;
				PopUpManager.addPopUp(rfidInfoBox,this,false);
				rfidInfoBox.x=point.x + 10;
				rfidInfoBox.y=point.y + 10;
			}			
		}
		
		public function updateRfidInfo(rfidinfo:String):void
		{
			if(rfidInfoBox)
			{	
				rfidInfoBox.update(rfidinfo);
				//var point:Point=new Point(this.x,this.y);
				//showThisWindow(point);
			}
		}

	}
}